<template>
    <div class="tab-bar-item" @click="itemClick">
        <div v-if="isActive">
            <slot name="item-icon-active"></slot>
        </div>
        <div v-else><slot name="item-icon" ></slot></div>
        <div :style="activeStyle">
            <slot name="item-text"></slot>
        </div>
        
    </div>
</template>

<script>
export default {
    props:{
        path:String,
        textColor:{
            type:String,
            default:'red'
        }    
    },
    data () {
        return {
            // isActive:false
        }
    },
    methods:{
        itemClick(){
            this.$router.push(this.path)
        }
    },
    computed: {
        isActive(){
            //等于-1是没找到
            //不等于-1是找到了 说明此路径为true其他的为false
            return this.$route.path.indexOf(this.path)!==-1
        },
       activeStyle(){
           return this.isActive?{color:this.textColor}:''
        },
    }
};
</script>

<style lang="less" scoped>
.tab-bar-item{
        flex: 1;
}
</style>

